﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mimoza.ObjectLayer;

namespace Mimoza.Apps.Console.Commands
{
    public partial class MoveHostCommandForm : Form
    {
        private Mimoza.Apps.Console.Application m_application;
        public  Mimoza.ObjectLayer.Container m_SelectedContainer;
        public MoveHostCommandForm()
        {
            InitializeComponent();
        }

        public void Init(Mimoza.Apps.Console.Application application)
        {
            m_application = application;

            treeView.Nodes.Clear();
            FillContainersTree(null, treeView.Nodes);

            treeView.ExpandAll();
        }
        private void FillContainersTree(object tag, TreeNodeCollection parentNodes)
        {
            foreach (Mimoza.ObjectLayer.Container cont in m_application.ContainersTreeViewModel.GetChildsContainers(tag as Mimoza.ObjectLayer.Container))
            {
                if (cont.Type > 0) continue;
                TreeNode treeNode = parentNodes.Add(cont.Name);                
                treeNode.Tag = cont;

                FillContainersTree(cont, treeNode.Nodes);
            }
        }
        private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            m_SelectedContainer = e.Node.Tag as Mimoza.ObjectLayer.Container;
            if (m_SelectedContainer.Type == 0)
            {
                this.bSelect.Enabled = true;
            }
            else {
                this.bSelect.Enabled = false;
            }
        }
    }
}
